package com.cpd.blog.controller;

import com.cpd.blog.dto.User.EditUserReq;
import com.cpd.blog.service.UserService;
import com.cpd.blog.dto.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户接口
 *
 * @author Copydown
 * @date 2021/8/17 13:37
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @ApiOperation("获取当前用户信息 接口")
    @GetMapping("/currentUser")
    public Result currentUser(@RequestHeader("apiToken") String token) {
        return userService.findUserByToken(token);
    }

    @ApiOperation("修改用户昵称 接口")
    @PostMapping("/editNickName")
    public Result editNickName(@RequestBody EditUserReq editUserReq) {
        return userService.editNickName(editUserReq.getNickName());
    }

    @ApiOperation("修改用户密码 接口")
    @PostMapping("/editPassword")
    public Result editPassword(@RequestBody EditUserReq editUserReq) {
        return userService.editPassword(editUserReq.getPassword(), editUserReq.getEmailCode());
    }

    @ApiOperation("发送邮箱验证码 接口")
    @PostMapping("/sendEmail")
    public Result sendEmail() {
        return userService.sendEmail();
    }

    @ApiOperation("用户个人信息卡片 接口")
    @PostMapping("/mineCard")
    public Result mineCard(@RequestHeader("apiToken") String token) {
        return userService.mineCard(token);
    }
}
